package com.th.admin.config;

import com.th.admin.interceptor.LoginInterceptor;
import com.th.admin.interceptor.RedisUrlCountInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ThreePure
 * @date 2022/4/19 8:44
 * @description: 配置拦截器
 * 1、编写一个拦截器（实现HandlerInterceptor接口）
 * 2、拦截器注册到容器中（配置类实现WebMvcConfigurer接口，重写addInterceptors方法）
 * 3、指定拦截规则【/** 静态资源也会被拦截】
 * @since 1.8
 */
@Configuration
public class AdminWebConfig implements WebMvcConfigurer {

    //@Autowired
    //RedisUrlCountInterceptor redisUrlCountInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加登录拦截器   /** 静态资源也会被拦截，注意要排除静态资源
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/", "/login", "/css/**", "/fonts/**", "/images/**", "/js/**");

        //添加redis计数拦截器
        /*registry.addInterceptor(redisUrlCountInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/", "/login", "/css/**", "/fonts/**", "/images/**", "/js/**");*/
    }
}
